package org.scboy.dbms.controller;

import java.util.List;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.dbms.service.BaseAreaConfigService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/base/areaconfig")
@Menu("微服务管理系统.区域编码映射类别")
public class BaseAreaConfigController {
	
	@Autowired
	BaseAreaConfigService  service;
	
	/**
	 * 分页查询区域编码映射类别
	 * @param request
	 * @return
	 */
	@PostMapping("page")
	@Permission("分页查询区域编码映射类别")
	public Result page(@RequestBody Model params){
		Page page=service.page(params);
		return Result.Success(page);
	}
	
	/**
	 * 新增区域编码映射类别
	 * @param request
	 * @return
	 */
	@PostMapping("add")
	@Permission("新增区域编码映射类别")
	public Result add(@RequestBody Model params){
		if(service.add(params)){
			return Result.Success("BASE_AREA_CONFIG_ADD_SUCCESS");
		}else{
			return Result.Error("BASE_AREA_CONFIG_ADD_ERROR");
		}
	}
	
	/**
	 * 更新区域编码映射类别
	 * @param request
	 * @return
	 */
	@PutMapping("update")
	@Permission("更新区域编码映射类别")
	public Result update(@RequestBody Model params){
		if(service.update(params)){
			return Result.Success("BASE_AREA_CONFIG_UPDATE_SUCCESS");
		}else{
			return Result.Error("BASE_AREA_CONFIG_UPDATE_ERROR");
		}		
	}

	/**
	 * 获取区域编码映射类别信息
	 * @param request
	 * @param id code
	 * @return
	 */
	@GetMapping("get")
	@Permission("根据主键获取区域编码映射类别信息")
	public Result get(String code){
		return Result.Success(service.get(code));
	}
	
	/**
	 * 根据主键删除区域编码映射类别
	 * @param request
	 * @param code 主键
	 * @return
	 */
	@DeleteMapping("delete")
	@Permission("根据主键删除区域编码映射类别")
	public Result delete(String code){
		if(service.delete(code)){
			return Result.Success("BASE_AREA_CONFIG_DELETE_SUCCESS");
		}else{
			return Result.Error("BASE_AREA_CONFIG_DELETE_ERROR");
		}
	}
	
	/**
	 * 查询区域编码映射类别集合
	 * @param request
	 * @return
	 */
	@GetMapping("list")
	@Permission("查询区域编码映射类别")
	public Result list(Model params){
		List<Model> list=service.list(params);
		return Result.Success(list);
	}
}
